<?php
// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | Author: create by allen.qiang
// +----------------------------------------------------------------------


/**
 * 评论操作功能
 * @package  htdocs
 * @subpackage  quanliadmin
 * @author   create by allen.qiang
 */

quanli_require('module/base/content/goodsComment.class.php');
quanli_require('module/base/customer/customerManage.class.php');

class pa_comment {
	//入口
	public function execute(){
		global $G_PGLOB;
		$operFlg = isset($_REQUEST['operFlg']) ? $_REQUEST['operFlg'] : null;
		switch ($operFlg){
			case 1:
				$this->init();
				break;
			case 2:
			case 3:
				$this->showAnswer();
				break;
// 			case 4:
// 				$this->showResult();
// 				break;
			default:
				$G_PGLOB->smarty->assign('error_msg','参数错误');
				$G_PGLOB->smarty->display('comm/errorDisplay.tpl');
				break;
		}
	}


	//页面初始化
	private function init() {
		global $G_PGLOB;
		//城市
		$G_PGLOB->smarty->assign_by_ref('city', $G_PGLOB->getCache('city'));
		$G_PGLOB->smarty->display('content/commentList.tpl');
	}
	
	private function showAnswer () {
		global $G_PGLOB;
		
		$operFlg = isset($_REQUEST['operFlg']) ? $_REQUEST['operFlg'] : null;
		
		$uuid = isset($_REQUEST['comment_id']) ? $_REQUEST['comment_id'] : null;

		$goodsComment = new goodsComment($G_PGLOB->DBCA);
		
		$comment_array = array('comment_id' => $uuid);
		
		$result_oneComment = $goodsComment->searchComments($comment_array);
		
		if (!empty($result_oneComment)){
			foreach ($result_oneComment as $commentList){
				//$commentList['info'] = htmlspecialchars($commentList['info']);
				$commentList['answer_content']= htmlspecialchars($commentList['answer_content']);
			}
			$commentInfo = $result_oneComment[0];


            //查询会员名
            $custID = '';

            $customerManage =new customerManage($G_PGLOB->DBCA);

            $arg_array = array(
                "pcustID" => $commentInfo["pcustID"]
            );
            $result_cust =$customerManage->getCustomerInfo($arg_array);

            if ( $result_cust ) {
                $custID = $result_cust[0];
            }

            $G_PGLOB->smarty->assign_by_ref('custID',$custID);


			$G_PGLOB->smarty->assign('commentInfo',$commentInfo);
		}

        $content_comments_item = new entity('content_comments_item');

        $comment_item_str = '';

        if (!empty($_REQUEST['comment_id'])) {

            $content_comments_item->comment_id = $_REQUEST['comment_id'];

            if (!$G_PGLOB->DBCA->fetch($content_comments_item)) {

                returnJsonData('没有找到当前信息', 404);
            }


            $sql = "SELECT comment_item FROM content_comments_item WHERE comment_id = ?";
            $item_temp_array = $G_PGLOB->DBCA->stmt_query( $sql, 'i', $_REQUEST['comment_id'] );


            if ( $item_temp_array ) {
                foreach($item_temp_array as $value) {

                    if ( $value->comment_item == 1 ){
                        $comment_item_str .= '非常好吃'."\t";

                    } elseif ( $value->comment_item == 2 ){
                        $comment_item_str .= '配送服务好'."\t";

                    } elseif ( $value->comment_item == 3 ){
                        $comment_item_str .= '口感细腻'."\t";

                    } elseif ( $value->comment_item == 4 ){
                        $comment_item_str .= '清甜可口'."\t";

                    } else {
                        $comment_item_str .= '蛋糕很漂亮';
                    }

                }
            }

        }


        $G_PGLOB->smarty->assign('comment_item_str',$comment_item_str);
		$G_PGLOB->smarty->display('content/commentDetail.tpl');
	}
}